package com.itheima.controller.backend.security.security;

import com.itheima.Service.OrderSettingService;
import com.itheima.common.entity.Result;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.OrderSettingDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {
    @Autowired
    OrderSettingService ordersettingService;

    @GetMapping("download")
    public void downloadFile(HttpServletResponse response) throws IOException {
        ordersettingService.downloadFile(response);

    }

    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(@RequestParam String month){
       List<OrderSettingDto>result= ordersettingService.getOrderSettingByMonth(month);
        return new Result(true,"获取预约设置数据成功",result);
    }

    @PostMapping("/editNumberByOrderDate")
    public Result getOrderSettingByMonth(@RequestBody OrderSetting orderSetting){
        ordersettingService.editNumberByOrderDate(orderSetting);
        return new Result(true,"预约设置成功",null);
    }

    //文件上传
    @PostMapping("/upload")
    public Result upload(@RequestParam("excelFile") MultipartFile excelFile) {
        try {
            ordersettingService.uploadFile(excelFile);
            return new Result(true, "预约设置成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "上传失败");
        }
    }
}
